const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info:{},
    canvasWidth: '', // canvas宽度
    canvasHeight: '', // canvas高度
    shareImg:'',
    show: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      statusHeight: app.gettop.height,
      status: app.gettop.status,
      navHeight:app.gettop.navHeight,
      mobbleBottom: app.mobile.mobbleBottom
    })
    this.data.info = JSON.parse(options.info)
    this.setData({
      info: this.data.info,
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.canvasdraw()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  onShareAppMessage: function () {
    return {
      title: '送你蜜链盟资产，点击领取',
      path: `/userPageA/pages/scan/receiving_assets/receiving_assets?id=` + this.data.info.orderId,
      imageUrl: this.data.shareImg
    }
  },
  canvasdraw: function (canvas) {
    console.log(1111111)
    var that = this;
    
    const ctx = wx.createCanvasContext('canvas')
    ctx.save()
    var path = "/images/canvas_bj.png";
    ctx.drawImage(path, 0, 0, 310, 247);
    ctx.restore()
    ctx.save()
    var str = '送你'
    // ctx.font = 'normal bold 20px sans-serif';
    ctx.setTextAlign('center'); // 文字居中
    ctx.setFillStyle("#FFF0D3");
    ctx.setFontSize(40)
    ctx.fillText(str, 310/2,65)
    // ctx.draw()
    
    var str2 = '￥' + this.data.info.giveTotal
    ctx.setFontSize(40)
    ctx.setFillStyle("#FFF0D3");
    ctx.setTextAlign('center');
    ctx.fillText(str2, 310/2,125)
    ctx.restore()
    ctx.save()
    var path2 = "/images/canvas_djlq.png";
    ctx.drawImage(path2, 46, 150, 220, 54);
    ctx.restore()
    ctx.draw()
    setTimeout(()=>{
      this.daochu()
    },500)
    
  },
  daochu(){
    console.log(1111)
    var _this = this
    wx.canvasToTempFilePath({
      x: 0,
      y: 0,
      width: 310,
      height: 247,
      destWidth: 620,
      destHeight: 494,
      fileType: 'jpg', //图片的质量，目前仅对 jpg 有效。取值范围为 (0, 1]，不在范围内时当作 1.0 处理。
      quality: 1,
      canvasId: 'canvas',
      success(res) {
        console.log(222)
        console.log(res.tempFilePath)
        _this.data.shareImg = res.tempFilePath
        _this.setData({
          img: res.tempFilePath
        })
      }
    })
  },
  copy(){ //复制
    wx.setClipboardData({
      data: this.data.info.orderNo,
      success (res) {
        wx.showToast({
          title: '复制成功',
        })
      }
    })    
  },
  black(){
    wx.reLaunch({
      // url: '/pages/assets/assets',
      url:'/pages/userMarket/userMarket'
    })
  }
})